home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1994 October / Macformat17.cdr / Shareware City / Developers / shutdown-fx-20-c / Fade module ƒ / ◊ Fades ƒ / Hilbert fade.c < prev    next >
C/C++ Source or Header  |  1994-07-11  |  4KB  |  154 lines

  1. /**********************************************************************\
  2.  
  3. File:        Hilbert wipe fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "timing.h"
  26.  
  27. /* This fills the screen by a Hilbert space-filling curve, which is defined by
  28.    two mutually recursive drawing functions:
  29.    
  30.    X = left, Y, draw, right, X, draw, X, right, draw, Y, left
  31.    Y = right, X, draw, left, Y, draw, Y, left, draw, X, right
  32.    
  33.    Start by drawing X at the highest recursion level from the bottomleft of the
  34.    screen. (At recursion level 1, X and Y are null functions.)
  35. */
  36.  
  37. #define    RecursionLevel    4
  38. #define CorrectTime 1
  39. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  40. #define theWindowWidth (boundsRect.right-boundsRect.left)
  41.  
  42. pascal void HilbertFadeRecurse(Rect boundsRect, Pattern *thePattern,
  43.     short level, short whichpattern, short* x, short* y, short* HilbertDirection,
  44.     short vBlockSize, short hBlockSize);
  45.  
  46. pascal short main(Rect boundsRect, Pattern *thePattern);
  47.  
  48.  
  49. pascal void HilbertFadeRecurse(Rect boundsRect, Pattern *thePattern,
  50.     short level, short whichpattern, short* x, short* y, short* HilbertDirection,
  51.     short vBlockSize, short hBlockSize)
  52. {
  53.     short            i;
  54.     Rect            source;
  55.     unsigned char    theChar;
  56.     
  57.     for (i=0; i<11; i++)
  58.     {
  59.         theChar=0xEE;
  60.         switch (i)
  61.         {
  62.             case 0:
  63.             case 10:
  64.                 theChar=(whichpattern==0) ? 0x02 : 0x01;
  65.                 break;
  66.             case 1:
  67.             case 9:
  68.                 theChar=(whichpattern==0) ? 0x69 : 0x42;
  69.                 break;
  70.             case 2:
  71.             case 5:
  72.             case 8:
  73.                 theChar=0x00;
  74.                 break;
  75.             case 3:
  76.             case 7:
  77.                 theChar=(whichpattern==0) ? 0x01 : 0x02;
  78.                 break;
  79.             case 4:
  80.             case 6:
  81.                 theChar=(whichpattern==0) ? 0x42 : 0x69;
  82.                 break;
  83.         }
  84.         
  85.         switch (theChar)
  86.         {
  87.             case 0x01:     /* turn left */
  88.                 (*HilbertDirection)--;
  89.                 if ((*HilbertDirection)<0) (*HilbertDirection)=3;
  90.                 break;
  91.             case 0x02:     /* turn right */
  92.                 (*HilbertDirection)++;
  93.                 if ((*HilbertDirection)==4) (*HilbertDirection)=0;
  94.                 break;
  95.             case 0x00:    /* draw */
  96.                 StartTiming();
  97.                 SetRect(&source, *x, *y-vBlockSize, *x+hBlockSize, *y);
  98.                 OffsetRect(&source, boundsRect.left, boundsRect.top);
  99.                 SectRect(&source, &boundsRect, &source);
  100.                 FillRect(&source, *thePattern);
  101.                 switch (*HilbertDirection)
  102.                 {
  103.                     case 0:
  104.                         *x+=hBlockSize;
  105.                         break;
  106.                     case 1:
  107.                         *y-=vBlockSize;
  108.                         break;
  109.                     case 2:
  110.                         *x-=hBlockSize;
  111.                         break;
  112.                     case 3:
  113.                         *y+=vBlockSize;
  114.                         break;
  115.                 }
  116.                 TimeCorrection(CorrectTime);
  117.                 break;
  118.             case 0x42:    /* call X */
  119.                 if (level>1)
  120.                     HilbertFadeRecurse(boundsRect,thePattern,level-1,0,x,y,
  121.                         HilbertDirection, vBlockSize, hBlockSize);
  122.                 break;
  123.             case 0x69:    /* call Y */
  124.                 if (level>1)
  125.                     HilbertFadeRecurse(boundsRect,thePattern,level-1,1,x,y,
  126.                         HilbertDirection, vBlockSize, hBlockSize);
  127.                 break;
  128.         }
  129.     }
  130. }
  131.  
  132. pascal short main(Rect boundsRect, Pattern *thePattern)
  133. {
  134.     short        curx, cury;
  135.     short        answer, i;
  136.     short        HilbertDirection;
  137.     short        vBlockSize;
  138.     short        hBlockSize;
  139.     
  140.     answer=1;
  141.     for (i=0; i<RecursionLevel; i++)
  142.         answer*=2;
  143.     vBlockSize=1+theWindowHeight/answer;    /* used to be 20 */
  144.     hBlockSize=1+theWindowWidth/answer;        /* used to be 32 */
  145.     HilbertDirection=0;
  146.     cury=theWindowHeight;
  147.     curx=0;
  148.     HilbertFadeRecurse(boundsRect,thePattern,RecursionLevel,0,&curx,&cury,
  149.         &HilbertDirection, vBlockSize, hBlockSize);
  150.     FillRect(&boundsRect, *thePattern);        /* in case we missed any bits */
  151.     
  152.     return 0;
  153. }
  154.